<?
$sub_menu = "230420";
include_once("./_common.php");

auth_check($auth[$sub_menu], "r");

$g4['title'] = "멤버쉽 상품";
include_once ("$g4[admin_path]/admin.head.php");

sql_query("alter table $mw_cash[membership_item_table] add mi_status char(1) default '1' not null", false);
sql_query("alter table $mw_cash[membership_item_table] add mi_discount char(1) default '' not null", false);

$colspan = 10;
?>

<?=subtitle($g4[title])?>

<table width=100% cellpadding=0 cellspacing=1>
<colgroup width=''>
<colgroup width=80>
<colgroup width=80>
<colgroup width=70>
<colgroup width=70>
<colgroup width=60>
<colgroup width=60>
<colgroup width=60>
<colgroup width=60>
<colgroup width=60>
<tr><td colspan='<?=$colspan?>' class='line1'></td></tr>
<tr class='bgcol1 bold col1 ht center'>
    <td> 멤버쉽 </td>
    <td> 기간 </td>
    <td> <?=$mw_cash[cf_cash_name]?> </td>
    <td> 누적 </td>
    <td> 현재 </td>
    <td> 사용 </td>
    <td> 연장만 </td>
    <td> 할인표시 </td>
    <td> 할인% </td>
    <td> <a href="mw.membership.item.form.php"><img src="<?=$g4[admin_path]?>/img/icon_insert.gif" border="0"></a> </td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>

<?
$t_acc = $t_now = 0;

$sql = "select * from $mw_cash[membership_item_table] order by ms_id, mi_day";
$qry = sql_query($sql);
for ($i=0; $row = sql_fetch_array($qry); $i++) { 

    // 멤버쉽이름
    $sql1 = "select * from $mw_cash[membership_table] where ms_id = '$row[ms_id]'";
    $row1 = sql_fetch($sql1);

    // 누적
    $sql2 = "select count(*) as cnt from $mw_cash[membership_log_table] where ml_day = '$row[mi_day]' and ms_id = '$row[ms_id]'";
    $row2 = sql_fetch($sql2);

    // 현재
    $sql3 = "select count(*) as cnt from $mw_cash[membership_log_table] where ml_day = '$row[mi_day]' and ms_id = '$row[ms_id]' and '$g4[time_ymdhis]' between ml_sdate and ml_edate";
    $row3 = sql_fetch($sql3);

    $t_acc += $row2[cnt];
    $t_now += $row3[cnt];

    $list = $i%2;
?>

<form name="fupdate<?=$row[mi_id]?>" method="post" action="mw.cs.update.php">
<input type="hidden" name="bo_table" value="<?=$bo_table?>">
<input type="hidden" name="mi_id" value="<?=$row[mi_id]?>">
<input type="hidden" name="w" value="u">

<tr class='list<?=$list?> col1 ht center'>
    <td> <?=$row1[ms_name]?> </td>
    <td style="text-align:right; padding-right:5px;"> <?=number_format($row[mi_day])?> 일 </td>
    <td style="text-align:right; padding-right:5px;"style="text-align:right; padding-right:5px;">
        <?=number_format($row[mi_cash])?> <?=$mw_cash[cf_cash_unit]?> </td>
    <td> <a href="javascript:membership_log(<?=$row[ms_id]?>, <?=$row[mi_day]?>, 0)"><?=number_format($row2[cnt])?> 명</a> </td>
    <td> <a href="javascript:membership_log(<?=$row[ms_id]?>, <?=$row[mi_day]?>, 1)"><?=number_format($row3[cnt])?> 명</a> </td>
    <td> <? if ($row[mi_status]) echo "√"; ?> </td>
    <td> <? if ($row[mi_renew]) echo "√"; ?> </td>
    <td> <? if ($row[mi_discount]) echo "√"; ?> </td>
    <td> <? echo $row[mi_status] ? mw_cash_membership_discount($row[mi_id]) : '0' ?>% </td>
    <td>
        <a href="mw.membership.item.form.php?mi_id=<?=$row[mi_id]?>&w=u"><img src="<?=$g4[admin_path]?>/img/icon_modify.gif"></a>
        <a href="javascript:del('mw.membership.item.update.php?w=d&mi_id=<?=$row[mi_id]?>');"><img src="<?=$g4[admin_path]?>/img/icon_delete.gif"></a>
    </td>
</tr>

</form>
<? } ?>

<?if (!$i)
        echo "<tr> <td style='height:100px; text-align:center;' colspan='$colspan' class='b'> 자료가 없습니다. </td></tr>";
?>

<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<tr class='bgcol1 bold col1 ht center'>
    <td colspan="3" style="font-weight:bold;"> 합 계 </td>
    <td> <a href="javascript:membership_log(0, 0, 0)"><?=number_format($t_acc)?> 명</a> </td>
    <td> <a href="javascript:membership_log(0, 0, 1)"><?=number_format($t_now)?> 명</a> </td>
    <td> &nbsp; </td>
    <td> &nbsp; </td>
    <td> &nbsp; </td>
    <td> &nbsp; </td>
    <td> &nbsp; </td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line1'></td></tr>
</table>

<script type="text/javascript">
function membership_log(ms_id, mi_day, acc) {
    location.href = "mw.membership.log.php?ms_id=" + ms_id + "&mi_day=" + mi_day + "&acc=" + acc;
}
</script>



<?
include_once ("$g4[admin_path]/admin.tail.php");
?>

